package com.pfzy.utildemo.activity.record.recording.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.pfzy.utildemo.R;
import com.pfzy.utildemo.activity.record.recording.callback.DialogCallBack;

/**
 * 司机录音弹窗
 */
public class UXDriverRecordingDialog extends Dialog implements View.OnClickListener {
    private DialogCallBack callBack;
    private View mContentView;

    public UXDriverRecordingDialog(@NonNull Context context, DialogCallBack callBack) {
        super(context);
        this.callBack = callBack;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window != null) {
            window.requestFeature(1);
            window.setBackgroundDrawable(new ColorDrawable(0));
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-2, -2);
            this.mContentView = LayoutInflater.from(getContext()).inflate(R.layout.uxdr_dialog, (ViewGroup) new FrameLayout(getContext()), false);
            setContentView(this.mContentView, params);
            setCancelable(false);
            setCanceledOnTouchOutside(false);
            createView();
        }
    }

    private void createView() {
        this.mContentView.findViewById(R.id.ux_tv_right).setOnClickListener(this);
        this.mContentView.findViewById(R.id.ux_tv_left).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        dismiss();
        if (v.getId() == R.id.ux_tv_right) {
            this.callBack.confirm();
        } else {
            this.callBack.cancel();
        }
    }
}
